import 'package:boss/color_constant.dart';
import 'package:boss/models/reback_order_list_data.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/page/takeoutManagement/page/rebackOrderDetail/widget/return_commodity_list.dart';
import 'package:boss/ui/page/takeoutManagement/page/takeoutDetail/takeout_detail_page.dart';
import 'package:boss/ui/page/takeoutManagement/page/takeoutProcess/widget/text_with_copy.dart';
import 'package:boss/ui/widget/button/radius_button.dart';
import 'package:boss/ui/widget/custom_divier.dart';
import 'package:boss/ui/widget/shadow_radius_card.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flustars/flustars.dart' as flustars;
import 'package:flutter/material.dart';

class AfterSaleItem extends StatelessWidget {
  final RebackOrderItem data;

  const AfterSaleItem({this.data});

  @override
  Widget build(BuildContext context) {
    return DefaultTextStyle(
      style: TextStyleConstant().normal_1_28,
      child: ShadowRadiusCard(
        margin: EdgeInsets.only(
          top: 30.w,
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Container(
              height: 82.w,
              padding: EdgeInsets.symmetric(horizontal: 20.w),
              decoration: BoxDecoration(
                  color: ColorConstant.ff5770f6.withOpacity(0.1),
                  borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(10.w),
                    topRight: Radius.circular(10.w),
                  )),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Text('售后单号：${data.refundId}', style: TextStyleConstant().normal_2_26),
                  Text(data.statusText, style: data.status == 2 ? TextStyleConstant().origin_24 : TextStyleConstant().blue_24),
                ],
              ),
            ),
            ReturnCommodityList(data: data),
            Container(
              height: 80.w,
              padding: EdgeInsets.symmetric(horizontal: 20.w),
              alignment: Alignment.centerLeft,
              child: Text(
                '退款金额',
                style: TextStyleConstant().normal_3_28,
              ),
            ),
            CustomDivider(),
            Container(
              padding: EdgeInsets.symmetric(
                vertical: 20.w,
                horizontal: 25.w,
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  _RowValue('退款总额', AmountUtil.price2String(data.rebackAmount)),
                  _RowValue('退款原因', data.backReason),
                  _RowValue('申请时间', data.ctime),
                  _RowValue(
                      '订单编号',
                      TextWithCopy(
                        data.takeOutId,
                        clipboardText: data.takeOutId,
                        textStyle: TextStyleConstant().normal_2_26,
                      )),
                  _RowValue('联系人', data.contactName),
                  _RowValue('联系电话', flustars.TextUtil.hideNumber(data.phoneNum)),
                ],
              ),
            ),
            Padding(
              padding: EdgeInsets.symmetric(
                horizontal: 65.w,
                vertical: 30.w,
              ),
              child: RadiusButton(
                width: double.infinity,
                height: 80.w,
                title: '查看订单',
                onTap: () {
                  Navigator.pushNamed(context, TakeoutDetailPage.pageName, arguments: {
                    'takeoutId': data.takeOutId
                  });
                },
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class _RowValue extends StatelessWidget {
  final String title;
  final dynamic value;

  const _RowValue(this.title, this.value) : assert(value is Widget || value is String);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(vertical: 10.w),
      child: Row(
        children: <Widget>[
          Text(
            '$title：${value is String ? value : ''}',
            style: TextStyleConstant().normal_2_26,
          ),
          if (value is Widget) value,
        ],
      ),
    );
  }
}
